local assets =
{
    -- Asset("ANIM", "anim/panda_fisherman_supply_pack.zip"),
    -- Asset( "IMAGE", "images/inventoryimages/panda_fisherman_supply_pack.tex" ),  -- 背包贴图
    -- Asset( "ATLAS", "images/inventoryimages/panda_fisherman_supply_pack.xml" ),
}

-----------------------------------------------------------------------------------------------
--- 灯光相关的控制
-- FRAMES
local function Light_Task_Start(inst)
	if not TheWorld.ismastersim then
		return
	end
	-- TheWorld.state.isday
	-- TheWorld.state.isdusk
	-- TheWorld.state.isnight
	local delta_num = 0.0025
	if TheWorld.state.isnight == true or TheWorld:HasTag("cave") then
		-- print("info:Light_Task_Start  On",inst.__light_up_num)

		----------------------------------------------------------
		-- 关掉旧的任务
		if inst.__light_up_task ~= nil then
			inst.__light_up_task:Cancel()
			inst.__light_up_task = nil
		end
		if inst.__light_off_task ~= nil then
			inst.__light_off_task:Cancel()
			inst.__light_off_task = nil
		end
		-----------------------------------------------------------

		inst.Light:Enable(true)
        inst.AnimState:ShowSymbol("glow")

		if inst.__light_up_num == nil then
			inst.__light_up_num = 0
		end

		inst.__light_up_task = inst:DoPeriodicTask(FRAMES,function()
			if inst.__light_up_num >= 0.75001 then
				inst.__light_up_task:Cancel()
				inst.__light_up_task = nil
				return
			end
			inst.Light:SetIntensity(inst.__light_up_num )
			inst.__light_up_num = inst.__light_up_num + delta_num
		end)
	elseif TheWorld.state.isday then	----------------- light  off
		-- print("info:Light_Task_Start  off")

		if inst.__light_up_task then
			inst.__light_up_task:Cancel()
			inst.__light_up_task = nil
		end

		if inst.__light_up_num == nil or inst.__light_up_num <= 0 then
			inst.Light:Enable(false)
            inst.AnimState:HideSymbol("glow")
			return
		end

		if inst.__light_up_num > 0 then
			inst.__light_off_task = inst:DoPeriodicTask(FRAMES,function()
				if inst.__light_up_num < 0 then
					inst.Light:Enable(false)
					if inst.__light_off_task then
						inst.__light_off_task:Cancel()
						inst.__light_off_task = nil
					end
					return
				end
				inst.Light:SetIntensity(inst.__light_up_num)
				inst.__light_up_num = inst.__light_up_num  - delta_num
			end)
		end
	else


	end
end
-----------------------------------------------------------------------------------------------

local function fn()
    TheSim:LoadPrefabs({ "quagmire_lamp_short" })
    local inst = CreateEntity()
    inst.entity:AddTransform()
    inst.entity:AddAnimState()
    inst.entity:AddLight()
    inst.entity:AddNetwork()

    MakeObstaclePhysics(inst, .5)

    inst.AnimState:SetBank("quagmire_lamp_short")
    inst.AnimState:SetBuild("quagmire_lamp_short")
    -- inst.AnimState:SetBloomEffectHandle("shaders/anim.ksh")
    inst.AnimState:PlayAnimation("idle")
    inst.AnimState:HideSymbol("glow")
    inst.Light:Enable(false)
    inst.Light:SetRadius(3)
    inst.Light:SetFalloff( 0.58)
    -- inst.Light:SetIntensity(0.75)
    inst.Light:SetIntensity(0)
    inst.Light:SetColour(200 / 255, 200 / 255, 200 / 255)
    inst:DoTaskInTime(0.5,function()
		Light_Task_Start(inst)
	end)


    inst.entity:SetPristine()
    if not TheWorld.ismastersim then
        return inst
    end

    -- -----------------------------------------------------------------------------------
	inst:WatchWorldState("isnight",function()	-------- 晚上
		if TheWorld.state.isnight then
			inst:DoTaskInTime(3,function()
				Light_Task_Start(inst)			
			end)
		end
	end)
    inst:WatchWorldState("cycles",function()	-------- 新的一天
		inst:DoTaskInTime(5,function()
            Light_Task_Start(inst)			
        end)
	end)
	-- -- -----------------------------------------------------------------------------------
    inst:DoTaskInTime(0,function()
        if inst.Ready ~= true then
            inst:Remove()
        end
    end)
    -----------------------------------------------------------------------------------
    return inst
end

return Prefab("npc_item_streetlight", fn,assets)